package models

import "gorm.io/gorm"

type Shop struct {
	gorm.Model
	Name  string  `json:"name" gorm:"type:varchar(60);unique"`
	Price float64 `json:"price" gorm:"type:decimal(10,2)"`
	Img   string  `json:"img" gorm:"varchar(255)"`
	Intro string  `json:"intro" gorm:"varchar(255)"`
}

func Add(shop *Shop) error {
	err = DB.Create(&shop).Error
	if err != nil {
		return err
	} else {
		return nil
	}
}
func Page(page, pageSize int) ([]Shop, int64, error) {
	var shop []Shop
	var total int64
	err = DB.Model(Shop{}).Count(&total).Error
	if err != nil {
		return nil, 0, err
	}
	err = DB.Model(Shop{}).Offset((page - 1) * pageSize).Limit(pageSize).Find(&shop).Error
	if err != nil {
		return nil, 0, err
	}
	return shop, total, err
}
